<?php

/**
 * becas_aplicables actions.
 *
 * @package    auip
 * @subpackage becas_aplicables
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class becas_aplicablesActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  
  public function executeIndex(sfWebRequest $request)
  {      
//      $valor = $request->getParameter('cantidad');
      
        $this->becas = new sfDoctrinePager('Beca', 5);      
      //$this->becas->setQuery(Doctrine::getTable('Beca')->createQuery('b')->where('b.registro_activo <> 0')->andWhere( '(b.fecha_fin - CURRENT_DATE) > 0')->addOrderBy('b.fecha_fin ASC') );
        //$this->becas->setQuery(Doctrine::getTable('Beca')->createQuery('b')->where('b.registro_activo <> 0')->addOrderBy('b.fecha_fin ASC') );
        $this->becas->setQuery(Doctrine::getTable('Beca')->createQuery('b')->select('nombre, (fecha_fin - current_date) as valor')->where('b.registro_activo <> 0')->andWhere('((fecha_fin - current_date) >= 0)')->addOrderBy('b.fecha_fin ASC'));
        $this->becas->setPage($request->getParameter('pagina', 1));
        $this->becas->init();
//          $query = "SELECT id, logo, nombre, fecha_fin, entidad_que_convoca as entidad FROM beca;";
//          $con = Doctrine_Manager::getInstance()->connection();
//          $resultado = $con->execute($query);
//          $this->convocatorias= $resultado->fetchAll();
         
  }
  
  public function executeEnviar_datos(sfWebRequest $request)
  {
      $valor = $request->getParameter('cantidad');
      $filas = '';
      if ($valor > 0)
      {
          $query = "SELECT b.logo, b.nombre, aab.atributo_valor as fecha_cierre ,b.entidad_que_convoca as entidad FROM ((beca as b INNER JOIN atributos_adicionales_beca as aab ON b.id = aab.beca_id) INNER JOIN atributos as a ON a.id = aab.atributo_id) WHERE (a.nombre IN ('fecha_cierre')) LIMIT 5 OFFSET ".$valor.";";
          $con = Doctrine_Manager::getInstance()->connection();
          $resultado = $con->execute($query);
          $convocatorias= $resultado->fetchAll();
          foreach ($convocatorias as $con):
            $fila .="<tr>";
            $fila .= "<td>".$con['logo']."</td>";
            $fila .= "<td>". $con['nombre']."</td>";
            $fila .= "<td>". $con['fecha_cierre']."</td>";
            $fila .= "<td>". $con['entidad']."</td></tr>";      
          endforeach;
      }      
      echo $filas;
      return sfView::NONE;
  }
  
  public function executeShow(sfWebRequest $request)
  {
    $this->beca = Doctrine_Core::getTable('Beca')->find(array($request->getParameter('id')));       
    //$this->beca = Doctrine_Core::getTable('Beca')->createQuery('b')->addWhere('b.id = ?', $request->getParameter('id'));       
    
    $this->forward404Unless($this->beca);    
  }
  
}
